ruleset rule infinite drift

Hi. Is there a way to deterministically create a ruleset_rule in via the Terraform PD provider whose position is codified as n + 1, where n is the existing index of the last rule in the relevant ruleset?

The context is we are in the middle of a large project to Terraform our PD config. As part of this, we created a single global ruleset for each monitoring service such as Datadog, Sumologic, etc.

We now are writing ruleset rules that live across our Terraform codebase, at the app state level.
Our initial thought was not to assign a deterministic position in Terraform per ruleset rule, and to let the ruleset logic determine priority. We thought this was easier because the ruleset rules live in different parts of the Terraform codebase, so it’s not easy for a developer to know what the position of the next rule on a global ruleset should be.

The problem we are running into is infinite drift on the ruleset rule position attribute. For example, having created the rules, we are seeing Terraform plans like these:

# pagerduty_ruleset_rule.some_rule has been changed
~ resource "pagerduty_ruleset_rule" "some_rule" {
<========== SENSITIVE CONTENT REMOVED ==========>
      ~ position = 0 -> 9
        # (2 unchanged attributes hidden)


        # (2 unchanged blocks hidden)
    }

Terraform will perform the following actions:

  # pagerduty_ruleset_rule.some_rule will be updated in-place
~ resource "pagerduty_ruleset_rule" "some_rule" {
<========== SENSITIVE CONTENT REMOVED ==========>
      - position = 9 -> null
        # (2 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Would love to be able to solve this problem without needing to do a lifestyle ignore or needing for each dev to look in PD UI to see the position of latest rule under relevant ruleset

Ok think I have a solution. If I set a new rule to the position of the catch all, PD will bump the catch all and it works

Hey Adam, sounds like you’ve got this one sorted out already.

Thanks for pointing that option out as well. I’m sure it will help someone else out in the future!